﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mapeo;
using NHibernate;
using BE;
using NHibernate.Criterion;
using MySql.Data.MySqlClient;
using System.Data;

namespace DAL
{
    public class SubsanarCursos_DAL:Controlador
    {


        public Int32 CicloMinimo(String CodigoAlumno)
        {
                Int32 resultado = 0;
                using (ISession Sesion = m_SessionFactory.OpenSession())
                {
                    using (ITransaction Trans = Sesion.BeginTransaction())
                    {
                        MySqlCommand SqlCmd = new MySqlCommand();
                        SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                        Trans.Enlist(SqlCmd);
                        SqlCmd.CommandText = "sp_ObtenerCicloAlumno";
                        SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                        SqlCmd.Parameters.AddWithValue("@inCodAlumno", CodigoAlumno);
                        SqlCmd.Parameters.AddWithValue("@inTipo", "Minimo");
                        SqlCmd.Parameters.Add("@outCiclo", MySqlDbType.Int32, 50);
                        SqlCmd.Parameters["@outCiclo"].Direction = ParameterDirection.Output;
                        SqlCmd.ExecuteNonQuery();
                        Trans.Commit();
                        resultado = Convert.ToInt32(SqlCmd.Parameters["@outCiclo"].Value);
                    }
                }
                return resultado;
        }

        public Int32 CicloMaximo(String CodigoAlumno)
        {
            Int32 resultado = 0;
            using (ISession Sesion = m_SessionFactory.OpenSession())
            {
                using (ITransaction Trans = Sesion.BeginTransaction())
                {
                    MySqlCommand SqlCmd = new MySqlCommand();
                    SqlCmd.Connection = (MySqlConnection)Sesion.Connection;
                    Trans.Enlist(SqlCmd);
                    SqlCmd.CommandText = "sp_ObtenerCicloAlumno";
                    SqlCmd.CommandType = System.Data.CommandType.StoredProcedure;
                    SqlCmd.Parameters.AddWithValue("@inCodAlumno", CodigoAlumno);
                    SqlCmd.Parameters.AddWithValue("@inTipo", "Maximo");
                    SqlCmd.Parameters.Add("@outCiclo", MySqlDbType.Int32, 50);
                    SqlCmd.Parameters["@outCiclo"].Direction = ParameterDirection.Output;
                    SqlCmd.ExecuteNonQuery();
                    Trans.Commit();
                    resultado = Convert.ToInt32(SqlCmd.Parameters["@outCiclo"].Value);
                }
            }
            return resultado;
        }
    }
}
